package com.wzcl.app.model.vo;

import com.wzcl.app.dao.model.ActivityRule;
import com.wzcl.app.model.common.WZCL;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


@EqualsAndHashCode(callSuper = false)
@Data
public class ActivityRuleVo extends BaseVo{
    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "活动Id")
    private Integer activityId;

    @ApiModelProperty(value = "作用对象")
    private Integer target;
    private String targetStr;

    @ApiModelProperty(value = "用户组Id")
    private Integer groupId;

    @ApiModelProperty(value = "优先级")
    private Integer orderNo;

    @ApiModelProperty(value = "详情")
    private List<ActivityRuleInfoVo> ruleInfoList;

    private ActivityRuleVo() {
    }


    public static ActivityRuleVo create(ActivityRule rule){
        ActivityRuleVo activityRuleVo = new ActivityRuleVo();
        BeanUtils.copyProperties(rule,activityRuleVo);
        if (rule.getRuleInfoList()!=null && rule.getRuleInfoList().size()>0){
            activityRuleVo.ruleInfoList = rule.getRuleInfoList().stream().map(ActivityRuleInfoVo::create).collect(Collectors.toList());
        }
        activityRuleVo.translationValueStr();
        return activityRuleVo;
    }

    @Override
    public void translationValueStr() {
        Map<String, Map<Integer, String>> map = getTranslationMap();
        this.targetStr=map.get(WZCL.GROUP_NAME.ACTIVITY_RULE_TARGET).get(this.target);
    }

    @Override
    public void processResources() {

    }
}
